package com.atlin.project.service.impl;

import com.atlin.project.contant.CommonConstant;
import com.atlin.project.model.dto.sysLogininfo.SysLogininfoQueryRequest;
import com.atlin.project.utils.sql.SqlUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atlin.project.model.domain.SysLogininfo;
import com.atlin.project.service.SysLogininfoService;
import com.atlin.project.mapper.SysLogininfoMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author atlin
 * @description 针对表【sys_logininfo(系统访问记录)】的数据库操作Service实现
 * @createDate 2024-09-04 18:41:08
 */
@Service
public class SysLogininfoServiceImpl extends ServiceImpl<SysLogininfoMapper, SysLogininfo>
        implements SysLogininfoService {

    @Override
    public QueryWrapper<SysLogininfo> getQueryWrapper(SysLogininfoQueryRequest sysLogininfoQueryRequest) {
        QueryWrapper<SysLogininfo> queryWrapper = new QueryWrapper<>();
        if (sysLogininfoQueryRequest == null) {
            return queryWrapper;
        }
        Long id = sysLogininfoQueryRequest.getId();
        String userAccount = sysLogininfoQueryRequest.getUserAccount();
        String ipaddr = sysLogininfoQueryRequest.getIpaddr();
        String loginLocation = sysLogininfoQueryRequest.getLoginLocation();
        String browser = sysLogininfoQueryRequest.getBrowser();
        String os = sysLogininfoQueryRequest.getOs();
        Integer status = sysLogininfoQueryRequest.getStatus();
        String msg = sysLogininfoQueryRequest.getMsg();
        Date loginTime = sysLogininfoQueryRequest.getLoginTime();
        String sortField = sysLogininfoQueryRequest.getSortField();
        String sortOrder = sysLogininfoQueryRequest.getSortOrder();

        queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
        queryWrapper.like(StringUtils.isNotBlank(userAccount), "userAccount", userAccount);
        queryWrapper.like(StringUtils.isNotBlank(ipaddr), "ipaddr", ipaddr);
        queryWrapper.like(StringUtils.isNotBlank(loginLocation), "loginLocation", loginLocation);
        queryWrapper.like(StringUtils.isNotBlank(browser), "browser", browser);
        queryWrapper.like(StringUtils.isNotBlank(os), "os", os);
        queryWrapper.eq(status >= 0, "status", status);
        queryWrapper.like(StringUtils.isNotBlank(msg), "msg", msg);
        queryWrapper.eq(loginTime != null, "loginTime", loginTime);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField),
                sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField);

        return queryWrapper;
    }
}




